package com.hbsx.why.ui.mine;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.hbsx.why.R;
import com.hbsx.why.base.BaseActivity;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * Created by User on 2017/8/29.
 */
public class SuggestActivity extends BaseActivity {
    @BindView(R.id.tv_topTitle)
    TextView tvTopTitle;
    @BindView(R.id.suggest_text)
    EditText suggestText;
    @BindView(R.id.text_count)
    TextView textCount;
    @BindView(R.id.commit)
    Button commit;
    private Context context = this;

    @Override
    protected int getLayoutResId() {
        return R.layout.ui_mine_suggest;
    }

    @Override
    protected void initView() {
        tvTopTitle.setText("意见反馈");
        suggestText.addTextChangedListener(watcher);
    }

    private TextWatcher watcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (s.length() > 150) {
                Toast.makeText(context, "字数过多将导致提交失败！", Toast.LENGTH_SHORT).show();
            }
            textCount.setText(s.length() + "/150");
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    };

    @OnClick(R.id.commit)
    public void onClick() {
        String text = suggestText.getText().toString();
        if (text.length() > 150) {
            Toast.makeText(context, "超过字数上限！", Toast.LENGTH_SHORT).show();
        } else {
            if (text.length() < 1) {
                Toast.makeText(context, "请填写意见再提交！", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context, "感谢您的宝贵意见，我们会越来越好！", Toast.LENGTH_LONG).show();
                suggestText.setText("");
                textCount.setText("0/150");
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
